package com.zxy.ziems.server.oauth.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.security.annotation.IgnoreLogin;
import com.zxy.ziems.server.oauth.service.BoeplatAauthService;
import com.zxy.ziems.server.oauth.vo.OauthToekenVo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 厂务登录
 */
@RestController
@RequestMapping("/api/ziems/auth")
public class ZiEmsOAuthController {

    @Autowired
    private BoeplatAauthService boeplatAauthService;


    /**
     * token回调
     * @param clientId
     * @param tenantId
     * @param code
     * @param httpResponse
     * @param appNum 移动端设备唯一识别code,若为null则是pc端
     * @return
     * @throws Exception
     */
    @IgnoreLogin
    @GetMapping("/token")
    public JsonResponse<OauthToekenVo> oauthToken(@RequestParam String clientId,
                                                  @RequestParam(required = false) String tenantId,
                                                  @RequestParam String code,
                                                  HttpServletResponse httpResponse, HttpServletRequest httpRequest,
                                                  @RequestParam(required = false) String appNum) throws Exception {
        //20230228临时功能：外网只允许白名单人员登录
        OauthToekenVo result = boeplatAauthService.oauthToken(clientId, tenantId, code, appNum, httpResponse, httpRequest);

        return JsonResponse.SUCCESS(result);
    }
}
